/**
 * Created by Administrator on 2015/9/6.
 */
var express = require('express');
var router = express.Router();
var adminService = require('../src/service/adminService');
var cusService = require('../src/service/cusService');

/**跳转到活动明细、接收get请求*/
router.get('/activityManage/toActivityDetail', function(req, res, next) {
    adminService.queryActiveDetail(req,function(result){
        res.render('EJS/admin/activityManage/activityDetail', { active: result });
    })
});

/**修改活动明细*/
router.post('/activityManage/activityDetail', function(req, res, next) {
    adminService.updateActiveDetail(req,function(result){
        //res.render('EJS/admin/activityManage/activityDetail', { active: result.code });
        res.redirect('/admin/activityManage/activityList?page=1');

    })
});

/**活动列表*/
router.get('/activityManage/activityList', function (req, res, next) {

    adminService.queryAllActive(req , function (result,param) {
        res.render('EJS/admin/activityManage/activityList', {actives: result,pages:req.query.page,param:param});
    });
});
/**活动明细*/
router.get('/activityManage/activityDetail', function (req, res, next) {
    res.render('EJS/admin/activityManage/activityDetail', {title: '�����'});
});
/**前往添加活动界面*/
router.get('/activityManage/toAddActivity', function (req, res, next) {
    res.render('EJS/admin/activityManage/addActivity', {title: '��ӻ', users:0});
});
/**添加活动*/
router.post('/activityManage/addActivity', function (req, res, next) {
    adminService.addActivity(req, res, function (result) {
        //if(result.content.affectedRows>=1){
            res.redirect('/admin/activityManage/activityList?page=1');
    })
});

/**邀请*/
router.get('/activityManage/invite', function (req, res, next) {
    adminService.insertInvite(req, res, function (result) {
        res.redirect('/admin/activityManage/activityList?page=1');
    })
});
/**前往邀请界面*/
router.get('/activityManage/toInvite', function (req, res, next){
    adminService.queryInvite(req, res, function (result) {
        res.render('EJS/admin/activityManage/invite', {answer: result.content,users:0,active:result.activeId});
    });
});
/**前往统计界面*/
router.get('/activityManage/toStatistic', function (req, res, next) {
    adminService.queryStatistic(req, function (a) {
        res.render('EJS/admin/activityManage/statistic', {actives: a});
    });

});
/**活动统计*/
router.get('/activityManage/statistic', function (req, res, next) {
    adminService.queryStatistic(req, function (result) {
        res.render('EJS/admin/activityManage/statistic', {actives: result});
    });
});
/**更新活动*/
router.get('/activityManage/delActivity', function (req, res, next) {
    res.render('EJS/admin/admin/updateActivity', {title: '�޸Ļ��Ϣ'});
});

/**删除活动**/

router.get('/activityManage/delActivityList', function (req, res, next) {
    adminService.delActivity(req, res, function (a) {
        res.redirect('/admin/activityManage/activityList?page=1');
    });
});


module.exports = router;